<%-- 
    Document   : userListEasyui
    Created on : 2019-9-27, 8:36:38
    Author     : danny
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jspf/top.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="${contextPath}/easyui/material-teal/easyui.css"/>
        <link rel="stylesheet" href="${contextPath}/easyui/icon.css"/>
        <script src="${contextPath}/easyui/jquery.min.js"></script>
        <script src="${contextPath}/easyui/jquery.easyui.min.js"></script>
        <script src="${contextPath}/easyui/easyui-lang-zh_CN.js"></script>
        <script>
            $(function () {
                $('#dg').datagrid({
                    title: '用户列表',
                    url: '${contextPath}/user/listdata.json',
                    pagination: true, pageSize: 5, pageList: [5, 10, 20],
                    columns: [[
                            {field: 'account', title: '账号', width: 100},
                            {field: 'userName', title: '姓名', width: 100},
                            {field: 'email', title: 'Email', width: 100, align: 'right'},
                            {field: 'mobile', title: '手机号', width: 100, align: 'right'}
                        ]],
                    toolbar: [{
                            iconCls: 'icon-add',
                            handler: function () {
                                $('#dd').dialog('open');
                            }
                        }, '-', {
                            iconCls: 'icon-help',
                            handler: function () {
                                alert('help')
                            }
                        }]
                });
                $('#dd').dialog({
                    title: 'My Dialog',
                    width: 400,
                    height: 200,
                    closed: true,
                    cache: false,
//                    href: 'get_content.php',
                    modal: true,
                    buttons: [{
                            text: '保存', iconCls: 'icon-ok',
                            handler: function () {
                                $('#myform').form('submit', {
                                    url:'${contextPath}/user/add/doajax.json',
                                    onSubmit: function () {
                                        console.log('进行验证');
                                    },
                                    success: function (data) {
                                        console.log(data);
                                        var result = JSON.parse(data);
                                        console.log(result.result);
                                        if (result.result) {
                                            console.log('success');
                                            $('#dd').dialog('close');
                                            $('#dg').datagrid('reload');
                                        }else {
                                            console.log('fail');
                                            $.messager.alert('提示','添加失败！<br>请稍后重试！','error');
                                        }
                                    }
                                });
                            }
                        }, {
                            text: '取消', iconCls: 'icon-cancel',
                            handler: function () {
                                $('#dd').dialog('close');
                            }
                        }]
                });
                $('#sex').combobox({
                    valueField: 'value',
                    textField: 'text',
                    data: [{text: '男', value: 'true'}, {text: '女', value: 'false'}]
                });
            });

        </script>
    </head>
    <body>
        <h1>Hello World!</h1>
        <table id="dg"></table>
        <div id="dd">
            <form action="" method="post" id="myform">
                <div><input type="text" class="easyui-textbox" name="account" value="${param.account}" label="账号："/></div>
                <div><input type="text" class="easyui-textbox" name="userName"  value="${param.userName}" label="姓名："/></div>
                <div><input type="password" class="easyui-passwordbox" name="password" label="密码："/></div>
                <div><input id="sex" class="easyui-combobox" name="sex" label="性别："/></div>

                <!--                <input type="radio" class="easyui-radiobutton" name="sex" value="true" />男&nbsp;&nbsp;&nbsp;
                                <input type="radio" id name="sex" value="false" />女<br>-->
                <!--<input type="submit" value="保存" />-->
            </form>
        </div>
    </body>
</html>
